<template>
  <h1>{{ num }}</h1>
  <button @click="num++">点击+1</button>
  <h1>{{ person }}</h1>
  <h1>姓名：{{ name }}</h1>
  <h1>年龄：{{ age }}</h1>
  <h1>薪资：{{ person.job.j1.salary }}K</h1>
  <button @click="name += '~'">修改姓名</button>
  <br />
  <button @click="age++">增长年龄</button>
  <br />
  <button @click="person.job.j1.salary++">涨薪</button>
</template>

<script>
// 体现出了组合式API的使用
import { reactive, ref, toRefs, shallowReadonly, readonly } from "vue";
export default {
  name: "myDemo",
  setup() {
    let num = ref(0);
    let person = reactive({
      name: "张三",
      age: 18,
      job: {
        j1: {
          salary: 10,
        },
      },
    });

    // person = readonly(person)
    person = shallowReadonly(person);
    num = readonly(num);

    return {
      num,
      person,
      ...toRefs(person),
    };
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped></style>
